iT邦幫忙

2024 iThome 鐵人賽

DAY 7
0
Python

一起來用 Snakify 練練手系列 第 7

【一起來用 Snakify 練練手】Day7 Lesson 3 練習題參考解答-1

  • 分享至 

  • xImage
  •  

Lesson3 有一些些題目需要多加思考
一樣下面也將提供各題參考解答
(⭐代表加碼題目)

前面幾題是蠻基本的正負判斷、基數、偶數

  • ⭐Is positive
a = int(input())
if a > 0:
    print('YES')
else:
    print('NO')
  • ⭐Is odd
a = int(input())
if a%2 == 0:
    print('NO')
else:
    print('YES')
  • ⭐Is even
a = int(input())
if a%2 == 0:
    print('YES')
else:
    print('NO')
  • ⭐Ends on seven
a = int(input())
if ((a-7)%10==0):
    print('YES')
else:
    print('NO')
  • Minimum of two numbers
a = int(input())
b = int(input())
if a-b>0:
    print(b)
else:
    print(a)
  • ⭐Are both odd
a = int(input())
b = int(input())

if (a%2==1 and b%2==1):
    print('YES')
else:
    print('NO')
  • ⭐At least one odd
a = int(input())
b = int(input())

if (a%2==1 or b%2==1):
    print('YES')
else:
    print('NO')
  • ⭐Exactly one odd
a = int(input())
b = int(input())

if (a%2==1 and b%2==0) or (a%2==0 and b%2==1):
    print('YES')
else:
    print('NO')
  • Sign function
a = int(input())

if a==0:
    print('0')
elif a>0:
    print('1')
else:
    print('-1')
  • ⭐Numbers in ascending order
a = int(input())
b = int(input())
c = int(input())

if a < b and b < c:
    print('YES')
else:
    print('NO')
  • ⭐Is three digit
a = int(input())

if (100<=a<=999):
    print('YES')
else:
    print('NO')
  • Minimum of three numbers
a = int(input())
b = int(input())
c = int(input())

if (a<b and a<c):
    print(a)
elif(b<a and b<c):
    print(b)
else:
    print(c)
  • Equal numbers
a = int(input())
b = int(input())
c = int(input())

if (a==b and b==c):
    print('3')
elif (a==b or a==c or b==c):
    print('2')
else:
    print('0')

上一篇
【一起來用 Snakify 練練手】Day6 Lesson 3 概念
下一篇
【一起來用 Snakify 練練手】Day8 Lesson 3 練習題參考解答-2
系列文
一起來用 Snakify 練練手30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言